# Contributor: qaqland <qaq@qaq.land>
# Maintainer: qaqland <qaq@qaq.land>
pkgname=xmake
pkgver=2.9.1
pkgrel=0
pkgdesc="A cross-platform build utility based on Lua"
url="https://xmake.io/"
arch="all"
license="Apache-2.0"
options="net"
depends="bash"
makedepends="
	readline-dev
	ncurses-dev
	linux-headers
	libsv-dev
	lua5.4-dev
	lz4-dev
	xxhash-dev
	libtbox-dev
	"
checkdepends="7zip"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-zsh-completion
	$pkgname-fish-completion
	"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/xmake-io/xmake/archive/refs/tags/v$pkgver.tar.gz
	01-pkgconfig-libsv.patch
	02-system-include.patch
	"

prepare() {
	default_prepare
	# Cleanup bundled deps
	rm -rf core/src/lua-cjson/*/
	rm -rf core/src/lua/*/
	rm -rf core/src/luajit/*/
	rm -rf core/src/lz4/*/
	rm -rf core/src/pdcurses/*/
	rm -rf core/src/sv/*/
	rm -rf core/src/tbox/*/
	rm -rf core/src/xxhash/*/
	# Remove complicated toolchain tests
	rm -rf tests/projects

	sed -i '1 s|#!/bin/sh|#!/bin/bash|' configure
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--external=yes \
		--kind=shared
	make
}

check() {
	cp build/xmake xmake/xmake
	cp scripts/xrepo.sh xmake/xrepo
	PATH="$PATH:$builddir/xmake"; \
		xmake lua -v -D tests/run.lua; \
		xrepo --version
}

package() {
	make DESTDIR="$pkgdir" install

	install -Dm644 scripts/man/*1 -t "$pkgdir"/usr/share/man/man1/

	install -Dm644 xmake/scripts/completions/register-completions.bash \
		"$pkgdir"/usr/share/bash-completion/completions/xmake
	install -Dm644 xmake/scripts/completions/register-completions.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_xmake
	install -Dm644 xmake/scripts/completions/register-completions.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/xmake.fish
}

sha512sums="
9e5bbab9c3025c522af5d4cd8e1349a641147fd53618ba6ab223491cc08bf3bf99b3e1d5d4910de55007dd575f79451d31806aa9d83d69c72b55b48c05e4c3a6  xmake-2.9.1.tar.gz
a2799a33230c849102f27e15c44b3972691132f551d7a571ed5c8d99a628d2f1923f093bcc41cc2b11c9fd431dfa4b2cb71438530ed3fe2c2daa656530a2fccc  01-pkgconfig-libsv.patch
735560bb8a148818b3c1efeac612c2873c473fd6727e749de78053442fda09919e51292f1aae71e49e5b22ab432da0a981d2d7505bd6e25ae02e4b40b6084279  02-system-include.patch
"
